https://leetcode.cn/problems/apple-redistribution-into-boxes/description/


class Solution {
public:
    int minimumBoxes(vector<int>& apple, vector<int>& capacity) {

        int sum = 0;
        for (int i = 0; i < apple.size(); i++)
            sum += apple[i];

        int cnt = 0;
        sort(capacity.begin(), capacity.end());

        for (int i = capacity.size() - 1; i >= 0; i--)
        {
            if (sum > 0)
            {
                sum -= capacity[i];
                cnt++;
            }
            else
            {
                break;
            }
        }
        return cnt;
    }
};